import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import pinia from './stores'
import Antd from 'ant-design-vue'
import 'ant-design-vue/dist/reset.css'
import 'uno.css'
import { setupGlobalComponents, AnyMessageBox } from './components'
import * as Sentry from '@sentry/vue'

import { setupErrorHandler } from './plugins/errorHandler'

// vConsole 配置开关
const ENABLE_VCONSOLE = false // 设置为 false 可以隐藏 vConsole

// 条件引入 vConsole
let vConsole: any = null
if (ENABLE_VCONSOLE) {
  // 动态引入 vConsole
  import('vconsole').then((VConsole) => {
    // 创建 vConsole 实例
    vConsole = new VConsole.default({
      theme: 'dark', // 设置主题为暗色
      defaultPlugins: ['system', 'network', 'element', 'storage'], // 默认显示的插件
      maxLogNumber: 1000, // 最大日志数量
      onReady: function() {
        console.log('vConsole is ready.')
      }
    })
  })
}

const app = createApp(App)

// 初始化 Sentry
Sentry.init({
  app,
  dsn: 'https://b5ec04b489d07982c5e8822e9e77a03d@o4509551336161280.ingest.us.sentry.io/4509562468040704',
  integrations: [
    Sentry.browserTracingIntegration({
      router,
    }),
  ],
  tracesSampleRate: 1.0,
  beforeSend(event) {
    console.log('Sentry Event:', event)
    return event
  },
})

app.use(pinia)
app.use(router)
app.use(Antd)

// 设置全局错误处理器
setupErrorHandler(app)

// 注册全局组件
setupGlobalComponents(app)

// 添加全局属性
app.config.globalProperties.$AnyMessageBox = AnyMessageBox

app.mount('#app')
